﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RecruitStudents.Utility;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility.Model;
using RecruitStudents.Utility.Helper;
using DevExpress.XtraEditors;

namespace RecruitStudents.Client.Lottery
{
    public delegate void DistributionEventHandler(object sender, EventArgs e);
    public delegate void DoubleClickEventHandler(object sender, EventArgs e);
    public partial class LotteryMakeLotteryForm_First_ExamRoomControl : UserControl
    {
        ServiceLottery service = new ServiceLottery();
        public LotteryMakeLotteryForm_First_ExamRoomControl()
        {
            InitializeComponent();
        }

        public LotteryMakeLotteryForm_First_ExamRoomControl(string examRoomId, string strGroupNO, string examRoomName)
            : this()
        {
            ExamRoomId = examRoomId;
            GroupNO = strGroupNO;
            ExamRoomName = examRoomName;
        }

        public void DataGridBind()
        {
            using (DataTable dt = service.GetPad_QueueDataTable(ExamRoomId,GroupNO))
            {
                gridControl2.DataSource = dt;
                if (dt != null)
                {
                    Text = ExamRoomName + " (" + dt.Rows.Count.ToString() + ") ";
                }
                else
                {
                    Text = ExamRoomName + " (0) ";
                }
            }
        }

        public string ExamRoomName { get; set; }
        public string ExamRoomId { get; set; }
        public string GroupNO { get; set; }

        public event DistributionEventHandler Distribution;
        public event DoubleClickEventHandler GridViewDoubleClick;
        protected void OnDistribution(object sender, EventArgs e)
        {
            if (Distribution != null)
            {
                Distribution(sender, e);
            }
        }
        protected void OnGridViewDoubleClick(object sender, EventArgs e)
        {
            if (GridViewDoubleClick != null)
            {
                GridViewDoubleClick(sender, e);
            }
        }

        public override string Text
        {
            get { return this.groupControl1.Text; }
            set { this.groupControl1.Text = value; }
        }

        private void btn_Distribution_Click(object sender, EventArgs e)
        {
            OnDistribution(this, e);
        }

        private void gridView2_DoubleClick(object sender, EventArgs e)
        {
            if (gridView2.GetFocusedValue() != null)
            {
                if (XtraMessageBox.Show("是否确认取消该考生的排队信息？", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    var strQueueID = gridView2.GetFocusedRowCellValue("QueueID").ToString();
                    bool flag = service.CancelExamRoomQueue(strQueueID);
                    if (flag)
                    {
                        DataGridBind();
                    }
                }
                OnGridViewDoubleClick(this, e);
            }
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            //DataTable dtReportDataSources = service.GetPad_Queue_PrintDataTable(SessionerHelper.ExamLevel, ExamRoomId.ToSafeString(), GroupNO.ToSafeString());
            //if (dtReportDataSources == null || dtReportDataSources.Rows.Count == 0)
            //{
            //    DevHelper.ShowErrorMessageBox("您选择的考场暂时没有数据进行打印!");
            //    return;
            //}
            //if (!dtReportDataSources.Columns.Contains("XH"))
            //{
            //    dtReportDataSources.Columns.Add("XH", typeof(int));
            //    for (int i = 0; i < dtReportDataSources.Rows.Count; i++)
            //    {
            //        dtReportDataSources.Rows[i]["XH"] = i + 1;
            //    }
            //}
            //var title = DateTime.Now.Year.ToString() + "同济大学艺术类专业招生考试";
            //string strGroupName = string.Empty;
            //TB_Sys_ExamPlaceSpecialityKindsGroupMapping model = new RecruitStudents.CommData.Service.ServiceControlDataSource().GetAppointmentGroupModel(GroupNO);
            //if (model != null)
            //{
            //    strGroupName = model.GroupName;
            //}

            //var subtitle = "----" + SessionerHelper.ExamPlaceName + ExamRoomName + SessionerHelper.ExamLevelName + strGroupName + "签到表";

            // Report_Print print = new Report_Print(dtReportDataSources, title, subtitle, ConstReportType.PrintStudentYUYUE);
            //print.ShowDialog();
        }
    }
}
